<?php
include ("../include/config.php");

require($config['basedir']."/include/authenticate.php");
require($config['basedir']."/admin/classes/banner.class.php");
//chk_permission('banners');
$post = $_POST;
$obj_banner = new Banners();
$_action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'view';

switch($_action) {
	case 'changeStatus':
		$obj_banner->changeStatus($post);
	break;	
		
	case 'add':
		if (isset($_POST['submit']))
		{
			$obj_banner->addBanner($post);
		}
	    stemplate::assign("post", $post);	
		stemplate::display("admin/banners/save.tpl");
		
	break;
	
	case 'edit':
		
		if (isset($post['submit']))
		{
			$obj_banner->updateBanner($post);
		}
	
		$id = isset($_REQUEST['banner_id']) ? $_REQUEST['banner_id'] : 0;
		$banner_data = $obj_banner->getBannerById($id);
		stemplate::assign("post", $banner_data);
		stemplate::display("admin/banners/save.tpl");
	break;
	
	case 'update':
		$post = $_POST;
		//print_r($post);exit;
		if( $obj_banner->updateBanner($post) ) 
		{
		    
			redirect("admin/banners/list.tpl?updated=1");			
		}
		else
		{
			
			$id = isset($_REQUEST['banner_id']) ? $_REQUEST['banner_id'] : 0;
		$banner_data = $obj_banner->getBannerById($id);
		stemplate::assign("id", $id);
		$pg = isset($_REQUEST['pg']) ? $_REQUEST['pg'] : 0;
		$ipp = isset($_REQUEST['ipp']) ? $_REQUEST['ipp'] : 0;
		$new_page_limit = isset($_REQUEST['new_page_limit']) ? $_REQUEST['new_page_limit'] : 0;
		stemplate::assign("pg", $pg);
		stemplate::assign("ipp", $ipp);
		stemplate::assign("new_page_limit", $new_page_limit);
		$size_data = $obj_banner->getBannerSize();
		$banner_cat = $obj_banner->getBannerCategories();
		stemplate::assign('size_data', $size_data);
		stemplate::assign('banner_cat', $banner_cat);
		stemplate::assign("post", $post);
		stemplate::display("admin/banners/edit.tpl");
			
				
		
		}
	
	break;
	
	case 'delete':
	    chk_permission('banners','delete');
		$id = isset($_REQUEST['banner_id']) ? $_REQUEST['banner_id'] : 0;
		$obj_banner->deleteBanner($id);
		global $pager;
		stemplate::assign("post", $post);
		$banner_list = $obj_banner->getBanners($post);
		//print_r($banner_list);exit;
		stemplate::assign('banner_list', $banner_list);
		stemplate::assign("total_records", $pager->items_total);
  		stemplate::assign("pagination_start", $pager->low);
  		stemplate::assign("pagination",$pager->display_pages());
		stemplate::assign("page_limit_select", $pager->display_page_limits());
		stemplate::display("admin/banners/list.tpl");
		
	break;	
	
	
	case 'view':
		chk_permission('banners','add');
	default:
		$post = $_REQUEST;
		if($_REQUEST['added'] == 1)	{
			global $msgOk;
			$msgOk = 'Banner added successfully.';
		}elseif($_REQUEST['updated'] == 1){
			global $msgOk;
			$msgOk = 'Banner updated successfully.';
		}elseif($_REQUEST['deleted'] == 1){
			global $msgOk;
			$msgOk = 'Banner deleted successfully.';
		}
		
		stemplate::assign("post", $post);
		$banner_list = $obj_banner->getBanners($post);
		
		
		stemplate::assign('banner_list', $banner_list);
		stemplate::assign("total_records", $pager->items_total);
  		stemplate::assign("pagination_start", $pager->low);
  		stemplate::assign("pagination",$pager->display_pages());
		stemplate::assign("page_limit_select", $pager->display_page_limits());
		stemplate::assign("banner_postion_array", $banner_postion_array);
		stemplate::display("admin/banners/list.tpl");
		
    break; 

}




?>